crypto: add signDigest/verifyDigest and Ed25519ctx support#62345
crypto: add signDigest/verifyDigest and Ed25519ctx support#62345panva wants to merge 2 commits intonodejs:mainfrom
Conversation
|
Review requested:
|
|
The
notable-change
Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62345 +/- ##
==========================================
- Coverage 91.60% 89.70% -1.91%
==========================================
Files 337 676 +339
Lines 140745 206807 +66062
Branches 21807 39616 +17809
==========================================
+ Hits 128933 185509 +56576
- Misses 11588 13444 +1856
- Partials 224 7854 +7630
🚀 New features to boost your workflow:
|
|
Not entirely certain how this works, will test |
regular
prehashed
Even though the digest is already computed, OpenSSL needs to know which digest was used:
Other key type dependant cases:
|
| break; | ||
| #else | ||
| if (can_throw) | ||
| crypto::CheckThrow(env, SignBase::Error::PrehashUnsupported); |
|
(nothing changed about the implementation, just extended test coverage) |
| bool EVPKeyCtxPointer::setSignatureMd(const Digest& md) { | ||
| if (!ctx_ || !md) return false; | ||
| return EVP_PKEY_CTX_set_signature_md(ctx_.get(), md.get()) == 1; | ||
| } |
There was a problem hiding this comment.
Is there a PR adding these into node/ncrypto yet? Preference would be to land these there first.
| * `callback` {Function} | ||
| * `err` {Error} | ||
| * `signature` {Buffer} | ||
| * Returns: {Buffer} if the `callback` function is not provided. |
There was a problem hiding this comment.
Really not a big fan of polymorphic returns. I'd prefer separate signDigest (async callback) and signDigestSync (sync returning Buffer) methods than one method that is either sync or async depending on how it's called.
There was a problem hiding this comment.
¯\_(ツ)_/¯
### `crypto.decapsulate(key, ciphertext[, callback])`
### `crypto.diffieHellman(options[, callback])`
### `crypto.encapsulate(key[, callback])`
### `crypto.randomBytes(size[, callback])`
### `crypto.randomInt([min, ]max[, callback])`
### `crypto.sign(algorithm, data, key[, callback])`
### `crypto.verify(algorithm, data, key, signature[, callback])`
Especially because of the last two i'm going to stick to this "convention" here.
There was a problem hiding this comment.
Yes, I've long despised this pattern and would really prefer that we not add to it. I wouldn't mind going back and revisiting these existing ones to add the Sync variants and deprecating the optional callback
There was a problem hiding this comment.
[, callback] appears in 77 distinct methods throughout various builtins, it is not just node:crypto. The pattern works and is wildly depended on for the existing methods, I disagree with changing it for the "same but slightly different" digest based sign/verify.
Furthermore a deprecation in these would be completely upside down since a sync version is the one without the currently optional callback. So a new method would have to be *Async which would be totally new in any builtin. Unless you're suggesting deprecating the default non-callback mode of these methods which I'm hoping you're not.
There was a problem hiding this comment.
Yes, I know the pattern is not limited to node:crypto... that doesn't mean I have to be a fan of it ;-)
What I would prefer these to be is something like
crypto.decapsulate(key, ciphertext, callback); // ok, always async
crypto.decapsulate(key, ciphertext); // sync, still works but missing callback deprecated
crypto.decapsulateSync(ke, ciphertext); // ok, always sync
// ...Rinse-repeat for each of the places where we see this pattern today.
I'm not going to block on it, just saying that I really wish we wouldn't keep perpetuating this maybe-sync-maybe-async pattern.
notable-changePRs with changes that should be highlighted in changelogs.
👇
Adds
crypto.signDigest()andcrypto.verifyDigest(), one-shot functions that sign/verify a pre-computed hash digest directly, without hashing internally.Supports RSA (PKCS#1 v1.5, PSS), ECDSA, DSA, Ed25519, Ed448, and ML-DSA (external mu).
Also adds Ed25519 context string support to
crypto.sign(),crypto.verify()as well as the new methods.Resolves: #60263
Pre-hash variants of Ed25519 and Ed448 as well Ed25519 context is defined in RFC8032